﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace kxjsj
{
    class Common
    {
        public static byte[] GetPdfFileBytes(string path)
        {
            byte[] data = null;
            using (FileStream fs = File.Open(path, FileMode.Open))
            {
                data = new byte[fs.Length];
                fs.Read(data, 0, data.Length);
            }
            return data;
        }

        public static void CreatePdfFile(byte[] data, string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                fs.Write(data, 0, data.Length);
            }
        }

        /// <summary>
        /// 判断两个数组相等
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="array1"></param>
        /// <param name="array2"></param>
        /// <returns></returns>
        public static bool ArrayEqals<T>(T[] array1, T[] array2)
        {
            if (array1 == array2) return true;
            if (array1 == null || array2 == null) return false;
            if (array1.Length != array1.Length) return false;
            Type equatable = typeof(T).GetInterface("IEquatable`1");
            if (equatable != null)
            {
                MethodInfo equalMethod = equatable.GetMethod("Equals", BindingFlags.Instance | BindingFlags.Public);
                for (int i = 0; i < array1.Length; i++)
                {
                    if (!(bool)equalMethod.Invoke(array1[i], new object[] { array2[i] })) return false;
                }
                return true;
            }
            Type comparable = typeof(T).GetInterface("IComparable`1");
            if (comparable != null)
            {
                MethodInfo compareMethod = comparable.GetMethod("CompareTo", BindingFlags.Instance | BindingFlags.Public);
                for (int i = 0; i < array1.Length; i++)
                {
                    if (!(bool)compareMethod.Invoke(array1[i], new object[] { array2[i] })) return false;
                }
                return true;
            }
            for (int i = 0; i < array1.Length; i++)
            {
                if (!array1[i].Equals(array2[i])) return false;
            }
            return true;
        }

    }
}
